<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="__static/css/public.css" media="all">
    <link rel="stylesheet" href="__static/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <style>
        .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
        .layui-table-cell {
            height: auto;
        }
        #rules {
            width: 50%;
            max-width: 100%;
        }
    </style>
</head>
<body>

<div class="layuimini-container">
    <div class="layuimini-main">
        <blockquote class="layui-elem-quote">
            <p><i class="fa fa-file-text"></i> 系统日志管理</p>
        </blockquote>

        <div class="layui-tab">
            <ul class="layui-tab-title">
                <li class="layui-this">操作日志</li>
                <li>用户日志</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <table class="layui-hide" id="logs" lay-filter="currentTableFilter"></table>
            
                    <script type="text/html" id="logsBar">
                        <a class="layui-btn layui-btn-normal layui-btn-xs role-edit" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-xs layui-btn-danger role-delete" lay-event="delete">删除</a>
                    </script>
                    <script type="text/html" id="logstype">
                        <span style="color: #4CAF50;font-weight: bold;{{d.type == 1?'':'display:none;'}}">新增</span>
                        <span  style="color: #03A9F4;font-weight: bold;{{d.type == 2?'':'display:none;'}}">修改</span>
                        <span  style="color: red;font-weight: bold;{{d.type == 3?'':'display:none;'}}">删除</span>
                        <span  style="color: #4CAF50;font-weight: bold;{{d.type == 4?'':'display:none;'}}">禁用</span>
                    </script>
                </div>
                <div class="layui-tab-item">
                    <table class="layui-hide" id="userLogs" lay-filter="currentTableFilter"></table>
            
                    <script type="text/html" id="userLogsBar">
                        <a class="layui-btn layui-btn-normal layui-btn-xs role-edit" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-xs layui-btn-danger role-delete" lay-event="delete">删除</a>
                    </script>

                </div>
            </div>
        </div>      
    </div>

</div>
<script src="__static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__static/js/man.js" charset="utf-8"></script>
<script>
    layui.use(['table', 'form', 'element'], function () {
        var $ = layui.jquery,
            table = layui.table,
            form = layui.form,
            element = layui.element,
            layer = layui.layer;

        // element.on('tab(switcher)');

        table.render({
            elem: '#logs',
            id: 'logs',
            url: '/system/logs/t/json',
            toolbar: true,
            cols: [[
                {field: 'id',  title: '#', align: 'center'},
                {field: 'username',  title: '用户'},
                {field: 'role_name',  title: '角色'},
                {field: 'site',  title: '操作'},
                {field: 'type',  title: '操作类型',toolbar:'#logstype'},
                {field: 'ip',  title: 'IP'},
                {field: 'create_time',  title: '时间',  templet: function(d){
			          return d.create_time?date('Y-m-d H:i:s',d.create_time):''
			    }},
            ]],
            page: true,
            skin: 'line'
        });

        table.render({
            elem: '#userLogs',
            id: 'userLogs',
            url: '/system/logs/t/json/a/user_logs',
            toolbar: true,
            cols: [[
                {field: 'id', width: 80, title: '#', align: 'center'},
                {field: 'username', width: 150, title: '用户'},
                {field: 'role_name', width: 100, title: '角色'},
                {field: 'method', width: 100, title: '方式'},
                {field: 'handle', width: 100, title: '操作'},
                {field: 'client_ip', width: 200, title: 'IP'},
                {field: 'position', width: 200, title: '定位'},
                {field: 'from', minWidth: 300, title: '来源'},
                {field: 'create_time', width: 160, title: '时间', fixed: 'right'},
            ]],
            page: true,
            skin: 'line'
        });

    
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('roleTable', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加新角色',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/system/role_edit.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('roleTable')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
            table.reload();
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/system/role_edit/id/' + data.id,
                    end: function() {
                        table.reload('roleTable');
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                var confirm = layer.confirm('删除角色 [' + data.name + ']？', {
                    yes: function(id) {
                        var url = '/system/role_del/id/' + data.id;
                        $.get(url, function(d) {
                            layer.msg(d.msg, {
                                time: 500
                            });
                            if (!d.code) {
                                obj.del();
                            }
                        });
                        layer.close(confirm);
                        // location.reload(1);
                    }
                });
            }
        });

    });
</script>
</body>
</html>